/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DedicacionView.java
 *
 * Created on 17-may-2012, 19:20:09
 */
package educar.abmDedicacion;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Flubber
 */
public class DedicacionView extends javax.swing.JFrame {


// <editor-fold defaultstate="collapsed" desc="Constructor">
    public DedicacionView() {
        initComponents();
    }
    // </editor-fold>

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbAgregar = new javax.swing.JButton();
        jbEliminar = new javax.swing.JButton();
        jbBuscar = new javax.swing.JButton();
        jlTitulo = new javax.swing.JLabel();
        jScrollPane = new javax.swing.JScrollPane();
        jtDedicacion = new javax.swing.JTable();
        jtfCriterio = new javax.swing.JTextField();
        jlCriterio1 = new javax.swing.JLabel();
        jlCriterio2 = new javax.swing.JLabel();
        jtfCriterio2 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jbAgregar.setText("Agregar");

        jbEliminar.setText("Eliminar");

        jbBuscar.setText("Buscar");

        jlTitulo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlTitulo.setText("Administracion de Dedicaciones");

        jtDedicacion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "DNI del Docente", "Codigo de Facultad", "Codigo de Cargo", "Dedicacion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane.setViewportView(jtDedicacion);
        jtDedicacion.getColumnModel().getColumn(0).setResizable(false);
        jtDedicacion.getColumnModel().getColumn(0).setPreferredWidth(15);

        jlCriterio1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jlCriterio1.setText("DNI del Docente");

        jlCriterio2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jlCriterio2.setText("Codigo de Facultad");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlTitulo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
                    .addComponent(jScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, 154, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlCriterio1))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtfCriterio2, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlCriterio2))
                        .addGap(23, 23, 23)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jlTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 311, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlCriterio1)
                            .addComponent(jlCriterio2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtfCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtfCriterio2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//<editor-fold defaultstate="collapsed" desc=" Declaracion de Variables ">    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbEliminar;
    private javax.swing.JLabel jlCriterio1;
    private javax.swing.JLabel jlCriterio2;
    private javax.swing.JLabel jlTitulo;
    private javax.swing.JTable jtDedicacion;
    private javax.swing.JTextField jtfCriterio;
    private javax.swing.JTextField jtfCriterio2;
    // End of variables declaration//GEN-END:variables
//</editor-fold>
   
    /**
     * <hr>
     * Tabla del Dedicacion
     * <hr>
     * @return jtDedicacion
     */    
    public JTable getJTDedicacion(){
        return this.jtDedicacion;
    }

    /**
     * <hr>
     * El modelo de la Tabla de la Dedicacion
     * <hr>
     * @return jtDedicacion
     */
    public DefaultTableModel getModeloTabla(){
        return (DefaultTableModel) jtDedicacion.getModel();
    }
    
    /**
     * <hr>
     * setModeloTabla: Modifica el modelo de la tabla a partir de un modelo
     * pasado como parametro.
     * <hr>
     * @param tabla modelo que va a tener la tabla
     */
    public void setModeloTabla(DefaultTableModel tabla){
        if (tabla != null){
            this.jtDedicacion.setModel(tabla);
        } else {
            jtDedicacion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "DNI del Docente", "Codigo de Facultad", "Codigo de Cargo", "Dedicacion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        }    
        jtDedicacion.getTableHeader().setReorderingAllowed(false);
        jScrollPane.setViewportView(jtDedicacion);
        jtDedicacion.getColumnModel().getColumn(0).setResizable(false);
        jtDedicacion.getColumnModel().getColumn(0).setPreferredWidth(15);
        jtDedicacion.getColumnModel().getColumn(1).setPreferredWidth(160);
        jtDedicacion.getColumnModel().getColumn(2).setPreferredWidth(160);
        jtDedicacion.getColumnModel().getColumn(3).setPreferredWidth(160);
        jtDedicacion.getColumnModel().getColumn(4).setPreferredWidth(160);
    }//Fin del metodo setModeloTabla()
    
    public JButton getJbAgregar() {
        return jbAgregar;
    }

    public JButton getJbBuscar() {
        return jbBuscar;
    }

    public JButton getJbEliminar() {
        return jbEliminar;
    }

    public String[] getCriterios() {
        String[] criterios = {jtfCriterio.getText(), jtfCriterio2.getText()};
        return criterios;
    }

    /**
     * <hr>
     * Asigna un Listener a los Botones
     * <hr>
     * @param listener
     */  
    public void setActionListener(DedicacionController listener) {
        jbAgregar.addActionListener(listener);
        jbEliminar.addActionListener(listener);
        jbBuscar.addActionListener(listener);
    }

    /**
     * <hr>
     * Asigna un Listener al Mouse
     * <hr>
     * @param listener
     */ 
    public void setMouseListener(DedicacionController listener) {
        jtDedicacion.addMouseListener(listener);
    }

    /**
     * <hr>
     * Asigna un Listener a la Ventana
     * <hr>
     * @param listener
     */
    public void setWindowListener(DedicacionController listener){
        this.addWindowListener(listener);
    }

}//Fin de la clase DedicacionView
